Handle websocket binary response from ComfyUI server#2
Handle websocket binary response from ComfyUI server#2guinoise wants to merge 2 commits intoandreyryabtsev:mainfrom
Conversation
Convert print to logger Add option to store output file in directory Add option to store preview images in a directory Change the README accordingly
andreyryabtsev
left a comment
There was a problem hiding this comment.
Thank you for this PR! Just took a brief pass with some comments, but looking forward to trying it locally + merging ASAP :)
| """Called when the prompt completes, with the final output.""" | ||
| @abc.abstractmethod | ||
| async def image_received(self, image: Image.Image): | ||
| """Called when the prompt's queue return a sampler image, a pillow image object is pass to this function""" |
There was a problem hiding this comment.
nit: "is pass" -> "is passed" + period at end just for consistency
| total = int(message["data"]["max"]) | ||
| await callbacks.in_progress(current_node, progress, total) | ||
| elif msg.type == aiohttp.WSMsgType.BINARY: | ||
| image= await receive_image(msg.data) |
| async def receive_image(image_data) -> Optional[Image.Image]: | ||
| ''' | ||
| Reference : https://github.com/comfyanonymous/ComfyUI.git server.py function send_image | ||
| Rebuild an PIL Image from the data received on the websocket. Return None on any errors. |
There was a problem hiding this comment.
nit: "a PIL image" + perhaps it's ok to skip the try and just let exception bubble up (ComfyAPI already throws exceptions)
| raise ValueError("\n" + "\n".join(errors)) | ||
|
|
||
| prompt_id = response_json['prompt_id'] | ||
| except aiohttp.client_exceptions.ContentTypeError as e: |
There was a problem hiding this comment.
can the except be moved up to only wrap the await resp.json() so any other errors bubble up normally?
| @@ -1,13 +1,27 @@ | |||
| """End-to-end example for creating an image with SDXL base + refiner""" | |||
There was a problem hiding this comment.
can we keep the file comment?
| import sys | ||
|
|
||
| formatter = logging.Formatter('%(asctime)s [%(levelname)-9s][%(name)-20s] %(message)s') | ||
| sh= logging.StreamHandler(stream=sys.stdout) |
There was a problem hiding this comment.
nit: space before "="/"+=" throughout the file to follow standard style?
When I tried the tool installed via pip, I got issues. The main cause of this is that the ComfyUI server return sampler images and that was not handled in the library. I fixed that and made some minor changes.
If you can accept the request and push a new version to pypi it will be greatly appreciated.
What changed :